<?php
@session_start();
require_once("../includes/conn.php");
$s= isset($_GET['s'])?$_GET['s']:'';
$phone= isset($_GET['phone'])?$_GET['phone']:'';
$type= isset($_GET['type'])?$_GET['type']:'';
$openid= isset($_GET['openid'])?$_GET['openid']:'';
$username = isset($_SESSION['nickname'])?$_SESSION['nickname']:'';
if ($openid)
{
	if ($s&&$type)
	{
		$exsits_fwm = mysql_fetch_array(mysql_query("select * from ".DBQIAN."fwm where fwm=".$s." and userstatus=0 order by id desc limit 1"));
		if ($exsits_fwm)
		{
			$result = $dbconn->fetch($dbconn->query("insert into ".DBQIAN."exchangeuser(fwm,credit,time,username,wx_user) values('".$s."',".$exsits_fwm['usercredit'].",'".date('Y-m-d H:s:i',time())."','".$username."','".$openid."')"));//插入红包记录
			$id = mysql_insert_id();
			//echo $id;exit;
			if ($id)
			{
				header("Location: ".WEBNAME."mobile/person.php?type=user&openid=".$openid);exit;
				//header("Location: ".WEBNAME."main/chaikai.index.php?sk=1445313033&sh=43920&s=".$s."&type=user&openid=".$openid."&phone=".$phone."&id=".$id);exit;
			}
			else 
			{
				header("Location: nowin.php?s=".$s."&openid=".$openid);exit;
			}
		}
		else 
		{
			header("Location: nowin.php?s=".$s."&openid=".$openid);exit;
		}
	}
	else 
	{
		header("Location: nowin.php?s=".$s."&openid=".$openid);exit;
	}
	//WEBNAME."main/chaikai.index.php?sk=1445313033&sh=43920&s=".$fwm['fwm']."&type=user&openid=".$openid
}
else
{
	header("Location: nowin.php?s=".$s."&openid=".$openid);exit;
}
